{ ID:asiapea1 PROG:msquare LANG:PASCAL } program msquare; const sn=40320; hn=40320; dx:array[1..3,1..8]of word=((8,7,6,5,4,3,2,1),(4,1,2,3,6,7,8,5),(1,7,2,4,5,3,6,8)); type state=array[1..8]of byte; var i,j,tt,step,wd,f,e,m,rn,oj:word; ss:array[1..sn]of state; tmp:state; hash:array[1..hn]of boolean; path:array[1..sn]of byte; pre:array[1..sn]of word; re:array[1..hn]of byte; // function hh(var s:state):word; var i,j,tt:word; n:array[1..8]of byte; begin fillchar(n,sizeof(n),0); for i:=1 to 7 do for j:=i+1 to 8 do if s[j]1 do begin inc(rn); re[rn]:=path[j]; j:=pre[j]; end; for j:=rn downto 1 do print(re[j]); print(i); writeln; close(output); halt; end; if not hash[tt] then begin hash[tt]:=true; ss[e]:=tmp; path[e]:=i; pre[e]:=f; inc(e); end; end; inc(f); if f=m then begin inc(step); m:=e; end; end; end.